import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import lazyplugin from 'vue3-lazy';
// 自定义loading指令
import loadingDirective from './components/base/loading/directive';
import noResultDirective from './components/base/no-result/directive';

// 全局引入样式文件
import '@/assets/scss/index.scss';

// 歌曲url失效处理
import { load, saveAll } from './assets/js/array-store';
import { FAVORITE_KEY, PLAY_KEY } from './assets/js/constant';
import { procressSongs } from './service/song';

const favoriteSongs = load(FAVORITE_KEY);
if (favoriteSongs.length > 0) {
  // 批处理
  procressSongs(favoriteSongs).then((songs) => {
    store.commit('setFavoriteList', songs);
    saveAll(songs, FAVORITE_KEY);
  });
}

const historySongs = load(PLAY_KEY);
if (historySongs.length > 0) {
  // 批处理
  procressSongs(historySongs).then((songs) => {
    store.commit('setPlayHistory', songs);
    saveAll(songs, PLAY_KEY);
  });
}

createApp(App).use(store).use(router).use(lazyplugin, {
  loading: require('./assets/image/default.png')
}).directive('loading', loadingDirective).directive('no-result', noResultDirective).mount('#app');
